import javax.swing.plaf.ListUI;
import java.awt.print.Book;
import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 杨已萱
 * Date: 2023-04-20
 * Time: 17:33
 */

public class MyarrayList<E> {
//    MyarrayList<Book> books= new MyarrayList<Book>();
public static void main1(String[] args) {
    Collection<String> list = new ArrayList<>();
    System.out.println(list.size());//计算大小
    System.out.println(list.isEmpty());//是否为空集合
    list.add("我");
    list.add("爱");
    list.add("Java");
    System.out.println(list.size());//计算大小
    System.out.println(list.isEmpty());//是否为空集合
    System.out.println(list);
    Object[] objects = list.toArray();//这个方法：返回一个装有所有集合中元素的数组用Object接收
    System.out.println(objects);//此时只打印了objects的哈希地址要重写方法
    System.out.println(Arrays.toString(objects));
    for (String x:list) {
        System.out.println(x);
    }
    list.remove("我");//只能移除元素不能移除下标
    System.out.println(list);
    for (String i:list) {
        System.out.println(i);
    }
    list.clear();
    System.out.println(list.size());
    System.out.println(list.isEmpty());

}
public static void main(String[] args) {
    List<String> courses = new ArrayList<>();
    courses.add("C");
    courses.add("JavaSE");
    courses.add("JavaEE");
    courses.add("计算机组成原理");
    courses.add("C++");
    courses.add("Javaweb");

    System.out.println(courses);

    System.out.println(courses.get(4));

//    List<String> subscourses = new ArrayList<>();
//    subscourses = courses.subList(2,4);//用原来的数组调用sublist截取用新的list接受
    List<String> subscourses = courses.subList(2,4);//原来的courses调用截取方法
                                                    // 直接赋给新ArrayList
    System.out.println(subscourses);
    System.out.println(courses);//截取并没有截掉?不不不拿到同一个地址
//    subscourses[0] = "hahah";//不能这样要用set方法！
    subscourses.set(0,"lalalalala");
    System.out.println("**************");
    System.out.println(subscourses);//两个都改了！拿到同一个地址
    System.out.println(courses);//两个都改了！拿到同一个地址
    System.out.println("**************");
    System.out.println("===============");
    //重新构造
    List<String> courses2 = new ArrayList<>(courses);//创建了副本
    System.out.println(courses2);
    System.out.println(courses2.get(2));//courses2也指向courses对象也能拿到下标
    courses2.set(1,"changed");//更改副本courses2的元素，courses不受影响
    System.out.println(courses);
    System.out.println(courses2);


}





}
